Homework 1

Author

Lauren Mezacapa

Published

September 9, 2024

Load Packages

library(Hmisc)
library(tidyverse)

Problem 1

Survey

August 29, 9:20 pm EST

Campuswire

This image shows top portion of the editor pane in RStudio with the image icon circled in red

How to insert an image into a Quarto document

Problem 2

Question 1

The population of data set 1 consists of individuals aged 16 or older who are not living in communal residences in England and Wales. The population of data set 2 consists of all crimes recorded and investigated by UK police forces.

Question 2

Data set 1 has a voluntary response as the strategy because the answers are self-reported. Data set 2 uses convenience as their strategy.

Question 3

Data set 1’s population is 38,000 people. Data set 2’s sampled population is the records

Question 4

data set 1’s target population is UK residence

Question 5

Data set 1 has somewhat reliability because it’s self reported and people could have lied, but reliability for data set 2 is reliable because it is records. The validity of data set 1 is good due to the large number of people and large age range. Demographic is good. Data set 2 also has good validity because it’s records. Data set 1’s study population is generalizable to the target population because of the large age range and amount of people included in the population. Data set 2 is also generalizable to the target population.

Problem 3

Question 1

The <- notation is equivalent to an = sign in R and is often used to declare variables. After running this code chunk, the named dataframe df appears in the environment on the right-hand side of RStudio.

df <- read_csv('https://www.openintro.org/data/csv/babies.csv')
Rows: 1236 Columns: 8
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (8): case, bwt, gestation, parity, age, height, weight, smoke

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Question 2

The notation Hmisc:: directly calls this function from the Hmisc package. describe() is a common function name, and sometimes this is needed to indicate to R which function from which package you want to use. The pipe feature |> sends the results of the first line directly into the function on the 2nd line and is a convenient way to chain functions together.

This code prints a useful and attractive summary of the data set we are using.

Hmisc::describe(df) |> 
  html()
df Descriptives
df

8 Variables   1236 Observations

case
image
        n  missing distinct     Info     Mean      Gmd      .05      .10      .25 
     1236        0     1236        1    618.5    412.3    62.75   124.50   309.75 
      .50      .75      .90      .95 
   618.50   927.25  1112.50  1174.25  
lowest : 1 2 3 4 5 , highest: 1232 1233 1234 1235 1236
bwt
image
nmissingdistinctInfoMeanGmd.05.10.25.50.75.90.95
123601071119.620.33 88.0 97.0108.8120.0131.0142.0149.0
lowest : 55 58 62 63 65 , highest: 169 170 173 174 176
gestation
image
nmissingdistinctInfoMeanGmd.05.10.25.50.75.90.95
1223131060.999279.316.57252.0262.0272.0280.0288.0295.8302.0
lowest : 148 181 204 223 224 , highest: 330 336 338 351 353
parity
nmissingdistinctInfoSumMeanGmd
1236020.573150.25490.3801

age
image
nmissingdistinctInfoMeanGmd.05.10.25.50.75.90.95
12342300.99727.266.50619202326313638
lowest : 15 17 18 19 20 , highest: 41 42 43 44 45
height
image
nmissingdistinctInfoMeanGmd.05.10.25.50.75.90.95
121422190.98664.052.83960616264666768
 Value         53    54    56    57    58    59    60    61    62    63    64    65
 Frequency      1     1     1     1    10    26    55   105   131   166   183   182
 Proportion 0.001 0.001 0.001 0.001 0.008 0.021 0.045 0.086 0.108 0.137 0.151 0.150
                                                     
 Value         66    67    68    69    70    71    72
 Frequency    153   105    54    20    13     6     1
 Proportion 0.126 0.086 0.044 0.016 0.011 0.005 0.001 
For the frequency table, variable is rounded to the nearest 0
weight
image
nmissingdistinctInfoMeanGmd.05.10.25.50.75.90.95
1200361050.999128.622.39102.0105.0114.8125.0139.0155.0170.0
lowest : 87 89 90 91 92 , highest: 215 217 220 228 250
smoke
nmissingdistinctInfoSumMeanGmd
12261020.7174840.39480.4782

Question 3

The Child Health and Development Studies investigate a range of topics. One study, in particular, considered all pregnancies between 1960 and 1967 among women in the Kaiser Foundation Health Plan in the San Francisco East Bay area. The variables in this data set are as follows.

Data Dictionary
Variable Name Variable Description Variable Type
case id number categorical, multicategorical
bwt birthweight, in ounces numerical
gestation length of gestation, in days numerical
parity binary indicator for a first pregnancy (0 = first pregnancy) categorical, binary
age mother’s age in years numerical
height mother’s height in inches numerical
weight mother’s weight in pounds numerical
smoke binary indicator for whether the mother smokes categorical, binary

Question 4

Below, 2 numeric variables were investigated for potential relationships. The independent, explanatory variable I chose is variable_name, and the dependent, response variable I chose is variable_name.

df |>
  ggplot(aes(x = gestation, # please change these
              y = bwt)) + 
  geom_point()
Warning: Removed 13 rows containing missing values or values outside the scale range
(`geom_point()`).

The highest birth weight is 100-150 between the gestation periods of 250-300

Session Info

This portion of the document describes the conditions in RStudio under which this report was created. This is important to include so that work is reproducible by others.

sessionInfo()
R version 4.2.1 (2022-06-23)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur ... 10.16

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] lubridate_1.9.3 forcats_1.0.0   stringr_1.5.1   dplyr_1.1.4    
 [5] purrr_1.0.2     readr_2.1.5     tidyr_1.3.1     tibble_3.2.1   
 [9] ggplot2_3.5.1   tidyverse_2.0.0 Hmisc_5.1-1    

loaded via a namespace (and not attached):
 [1] tidyselect_1.2.1  xfun_0.47         colorspace_2.1-1  vctrs_0.6.5      
 [5] generics_0.1.3    htmltools_0.5.8.1 yaml_2.3.10       base64enc_0.1-3  
 [9] utf8_1.2.4        rlang_1.1.4       pillar_1.9.0      foreign_0.8-87   
[13] glue_1.7.0        withr_3.0.1       bit64_4.0.5       lifecycle_1.0.4  
[17] munsell_0.5.1     gtable_0.3.5      htmlwidgets_1.6.4 evaluate_0.24.0  
[21] labeling_0.4.3    knitr_1.48        tzdb_0.4.0        fastmap_1.2.0    
[25] curl_5.2.2        parallel_4.2.1    fansi_1.0.6       htmlTable_2.4.3  
[29] scales_1.3.0      backports_1.5.0   checkmate_2.3.2   vroom_1.6.5      
[33] jsonlite_1.8.8    farver_2.1.2      bit_4.0.5         gridExtra_2.3    
[37] hms_1.1.3         digest_0.6.37     stringi_1.8.4     grid_4.2.1       
[41] cli_3.6.3         tools_4.2.1       magrittr_2.0.3    Formula_1.2-5    
[45] cluster_2.1.6     crayon_1.5.3      pkgconfig_2.0.3   data.table_1.16.0
[49] timechange_0.3.0  rmarkdown_2.28    rstudioapi_0.16.0 R6_2.5.1         
[53] rpart_4.1.23      nnet_7.3-19       compiler_4.2.1